<?php
session_start();
include './config.php';

if (!isset($_SESSION['username'])) {
    header("Location: ../login.php");
    exit();
}

header('Content-Type: application/json');

$qq = $_GET['qq'] ?? '';
$lxqq = $_POST['lxqq'] ?? '';
$type = $_POST['type'] ?? '';

if (empty($qq) || empty($lxqq) || empty($type)) {
    echo json_encode(["code" => "400", "msg" => "QQ号、授权人和类型不能为空"]);
    exit();
}

$updateStmt = $conn->prepare("UPDATE sq SET lxqq = ?, type = ? WHERE qq = ?");
$updateStmt->bind_param("ssi", $lxqq, $type, $qq);

if ($updateStmt->execute()) {
    echo json_encode(["code" => "200", "msg" => "编辑成功"]);
} else {
    echo json_encode(["code" => "500", "msg" => "编辑失败", "error" => $updateStmt->error]);
}

$conn->close();
?>